﻿using EasyTask.EasyEnum;
using SQLBuilder;

namespace EasyTask.Models
{
    /// <summary>
    /// 数据库中的配置类
    /// </summary>
    [Table("Base_Tasks")]
    public class Tasks
    {
        [Key]
        public string JobName { get; set; }
        public string JobGroupName { get; set; }
        public string JobTriggerName { get; set; }
        /// <summary>
        /// 该状态被ServiceState标识
        /// </summary>
        public int State { get; set; }
        /// <summary>
        /// 显示名称
        /// </summary>
        public string DisplayJobName { get; set; }
        /// <summary>
        /// Cron表达式
        /// </summary>
        public string Cron { get; set; }
        /// <summary>
        /// JobTriggerGroupName
        /// </summary>
        public string JobTriggerGroupName { get; set; }
        /// <summary>
        /// 每次进行操作后由EasyTask更新状态的显示信息
        /// </summary>
        public string DisplayStateDesc { get; set; }
        /// <summary>
        /// 手动停止后下次启动是否重新开始, 1是重新开始  0 是不重新开始
        /// </summary>

        public int? ManualStopIsStart { get; set; } = 1;

        [Column(Update = false, Insert = false)]
        public ServiceState ServiceState
        {
            get
            {
                switch (State)
                {
                    case 0: return ServiceState.PrepareStart;
                    case 1: return ServiceState.Started;
                    case 2: return ServiceState.PrepareStop;
                    case -2: return ServiceState.Stoped;
                    case 3: return ServiceState.PreparePasue;
                    case -3: return ServiceState.Paused;
                    case 4: return ServiceState.PrepareUpdate;
                    case -9: return ServiceState.ManualStoped;
                    default:
                        return ServiceState.Unknow;
                }
            }
        }
    }
}
